<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录</title>

    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .login-container {
            background: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
            width: 300px;
        }
        h2 {
            text-align: center;
            color: #333;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            width: 100%;
            padding: 10px;
            background-color: #5cb85c;
            border: none;
            color: white;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        button:hover {
            background-color: #4cae4c;
        }
        #message {
            margin-top: 15px;
            text-align: center;
            color: red;
        }
    </style>
</head>
<body>
<div class="login-container">
    <h2>用户登录</h2>
    <form id="loginForm">
        <div class="form-group">
            <label for="userName">用户名:</label>
            <input type="text" id="userName" name="userName" required>
        </div>
        <div class="form-group">
            <label for="password">密码:</label>
            <input type="password" id="password" name="password" required>
        </div>
        <button type="button" id="loginBtn">登录</button>
        <div id="message"></div>
    </form>
</div>

<script src="./js/jquery.min.3.6.0.js"></script>
<script>
    $(document).ready(function() {
        $("#loginBtn").click(function() {
            // 获取表单数据
            var userName = $("#userName").val();
            var password = $("#password").val();

            // 简单前端验证
            if (!userName || !password) {
                $("#message").text("用户名和密码不能为空");
                return;
            }

            // 发送GET请求（注意：密码明文传输不安全，仅作演示）
            $.ajax({
                url: "/system/sysUser/login", // 后端接口地址
                type: "GET",
                data: {
                    userName: userName,
                    password: password
                },
                success: function(response) {
                    $("#message").text(response);
                    if (response === "success") {
                        window.location.href = "./system/role/role_list.html"; // 登录成功后跳转到首页
                    }
                },
                error: function(xhr) {
                    // 处理错误响应
                    $("#message").text("请求失败！");
                }
            });
        });

        // 回车键触发登录
        $(document).keypress(function(e) {
            if (e.which == 13) {
                $("#loginBtn").click();
            }
        });
    });
</script>
</body>
</html>